<?php
error_reporting(E_ALL ^ E_NOTICE);

set_time_limit(0);
date_default_timezone_set("PRC"); //timezone

$db=mysql_connect("localhost","root","root"); 
mysql_select_db('faithwar',$db); 
 
//$logdate =  mysql_query("SELECT DISTINCT logdate FROM `report_nojailbreak`");
//$dateTime = date("Y-m-d",strtotime("-1 day"));
$dateTime = date("Y-m-d");
    //$deviceid = mysql_fetch_array($deviceid_query);
    //while($deviceid[deviceid])

//while($everylogdate = mysql_fetch_array($logdate))
//{

      //所有用户的等级 等级1 -10
    $p1date1Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM faithwar_level
        WHERE level = 1 ",$db);
    $p1date1Count_a = mysql_fetch_array($p1date1Count_query);
    $p1date1Count = $p1date1Count_a[0];
  
    $p1date2Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM faithwar_level
        WHERE level = 2 ",$db);
    $p1date2Count_a = mysql_fetch_array($p1date2Count_query);
    $p1date2Count = $p1date2Count_a[0];
  
    $p1date3Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM faithwar_level
        WHERE level = 3 ",$db);
    $p1date3Count_a = mysql_fetch_array($p1date3Count_query);
    $p1date3Count = $p1date3Count_a[0];

    $p1date4Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM faithwar_level
        WHERE level = 4 ",$db);
    $p1date4Count_a = mysql_fetch_array($p1date4Count_query);
    $p1date4Count = $p1date4Count_a[0];
  
    $p1date5Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM faithwar_level
        WHERE level = 5 ",$db);
    $p1date5Count_a = mysql_fetch_array($p1date5Count_query);
    $p1date5Count = $p1date5Count_a[0];
 
    $p1date6Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM faithwar_level
        WHERE level = 6 ",$db);
    $p1date6Count_a = mysql_fetch_array($p1date6Count_query);
    $p1date6Count = $p1date6Count_a[0];
 
    $p1date7Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM faithwar_level
        WHERE level = 7 ",$db);
    $p1date7Count_a = mysql_fetch_array($p1date7Count_query);
    $p1date7Count = $p1date7Count_a[0];
 
    $p1date8Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM faithwar_level
        WHERE level = 8 ",$db);
    $p1date8Count_a = mysql_fetch_array($p1date8Count_query);
    $p1date8Count = $p1date8Count_a[0];
   
    $p1date9Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM faithwar_level
        WHERE level = 9 ",$db);
    $p1date9Count_a = mysql_fetch_array($p1date9Count_query);
    $p1date9Count = $p1date9Count_a[0];
 
    $p1date10Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM faithwar_level
        WHERE level = 10 ",$db);
    $p1date10Count_a = mysql_fetch_array($p1date10Count_query);
    $p1date10Count = $p1date10Count_a[0];
  
     //p1等级分布 (1,2,....)
    $date = array('1' => array($p1date1Count, $date1), array($p1date2Count, $date2), array($p1date3Count, $date3), array($p1date4Count, $date4), array($p1date5Count, $date5), array($p1date6Count, $date6), array($p1date7Count, $date7), array($p1date8Count, $date8), array($p1date9Count, $date9), array($p1date10Count, $date10), array($p1date11Count, $date11), array($p1date12Count, $date12), array($p1date13Count, $date13), array($p1date14Count, $date14), array($p1date15Count, $date15), array($p1date16Count, $date16), array($p1date17Count, $date17), array($p1date18Count, $date18), array($p1date19Count, $date19), array($p1date20Count, $date20), array($p1date21Count, $date21));
   
    $level = array(json_encode($date));//等级分布 

    $sql2 = "UPDATE report_nojailbreak SET AllplayerLevel1= '$p1date1Count',AllplayerLevel2= '$p1date2Count',AllplayerLevel3= '$p1date3Count',AllplayerLevel4= '$p1date4Count',AllplayerLevel5= '$p1date5Count',AllplayerLevel6= '$p1date6Count',AllplayerLevel7= '$p1date7Count',AllplayerLevel8= '$p1date8Count',AllplayerLevel9= '$p1date9Count',AllplayerLevel10= '$p1date10Count',AllplayerLevel= '$level[0]' WHERE logdate= '$dateTime'";
if(mysql_query($sql2,$db)){
    echo "1 update is ok!";
} else {
    echo "failed£º".mysql_error();
}
 // }


mysql_close($db);
?>